package com.wars2donline.client.json;

import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import com.wars2donline.client.data.HeroData;
import com.wars2donline.client.util.Global;

public class JSONParser {
	
	JsonReader mJsonReader = null;
	
	class AnimData {
		String name;
		List<Integer> frames;
	}

	class Attributes {
		int damage;
		int hp;
		int mana;
	}
	
	class HeroInfo {
		String name;
		Attributes attrs;
		List<AnimData> anim;
	}
	
	public JSONParser() {
	}
	
	public void getHeroActor(int heroId, HeroData outData) {
		
		Reader reader = new InputStreamReader(Gdx.files.internal(Global.HERO_DIR + heroId + "/info.json").read());
		HeroInfo json = new Gson().fromJson(reader, HeroInfo.class);

		outData.damage = json.attrs.damage;
		outData.maxHp = json.attrs.hp;
		outData.maxMana = json.attrs.mana;
		
		outData.name = json.name;
		
		for (AnimData anim : json.anim) {
			if (anim.name.equals("idle")) {
				outData.idleAnimFrames = anim.frames;
			} else if (anim.name.equals("walk")) {
				outData.walkAnimFrames = anim.frames;
			}
		}
	}
}
